//获取当前时间以字符串形式显示在span标签内
//  2020/10/15 15:08:10
function loadTime(){
	var currentDate = new Date();
	var dateStr = formatDate(currentDate);
	var span = document.getElementById("s");
	span.innerText = dateStr;
}
//日期对象 转换为 指定日期格式的字符串 yyyy/MM/dd HH:mm:ss
function formatDate(date){
	var str = date.getFullYear()+"-"+subDate((date.getMonth()+1))+"-"
		+subDate(date.getDate())+"   "+subDate(date.getHours())+":"
		+subDate(date.getMinutes())+":"+subDate(date.getSeconds());
	return str;
}
//补全日期 不足两位前面补0  5--05 10--10
//先统一前面加0  05  010
function subDate(s){
	var s1 = "0"+s;
	return s1.substring(s1.length-2);
}

onload = function(){
	//每隔1秒 执行loadTime方法
	setInterval(loadTime,1000);
};